﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RoadTeam.Enums;
using System.Reflection;
using System.Data;
using RoadTeam.DAL;
using RoadTeam.Model;

public partial class 映射枚举值_GetEnumsDictionary : System.Web.UI.Page
{

    #region 获取单元数据
    public DataTable GetRtRmUnit()
    {
        String StrSql = @"SELECT UnitID,
UnitCode,
UnitName,
UnitFullName,
UnitIdentifier,
TbRmBuilding.OrganID as OrganID,
TbRmBuilding.BuildingName,
TbRmPavilion.PavilionName,
TbRmUnit.[Floor],
TbRmUnit.DoorTypeID
FROM TbRmBuilding 
INNER JOIN TbRmPavilion on TbRmBuilding.BuildingID=TbRmPavilion.BuildingID
INNER JOIN  TbRmUnit on TbRmUnit.PavilionID=TbRmPavilion.PavilionID
";

        StrSql = @"SELECT unitID,
unitcode,
unitname,
unitfullname,
UnitIdentifier,
TbRmBuilding.OrganID as OrganID,
TbRmBuilding.BuildingName,
TbRmPavilion.pavilionname,
TbRmUnit.[floor],
TbRmUnit.DoorTypeID,
TbRmUnit.pavilionID
FROM TbRmBuilding 
INNER JOIN TbRmPavilion on TbRmBuilding.BuildingID=TbRmPavilion.BuildingID
INNER JOIN  TbRmUnit on TbRmUnit.PavilionID=TbRmPavilion.PavilionID
";

        DataTable dt = DbFactory.CreateInstance().CreateDb().ExecuteStrQuery(StrSql, CommandType.Text, GlobalConfig.RtConnectionString);
        return dt;
    }
    public DataTable GetRmUnit()
    {
        SqlWhere where = new SqlWhere();
        where.SelectColumn = @"UnitName as unitnames,
UnitIdentifier,UnitName,UnitCode	,
UnitFullName,DoorTypeIdentifier,
OrganIdentifier,BuildingName,PavilionName	,[Floor]";

        return RoadTeam.Model.RmUnit.Select(where, GlobalConfig.ConnectionString);
    }
    #endregion



    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Dictionary<String, ColumnInfo> Dict = RoadTeam.Pub.SyncTable.GetDict("UnitColumnDictionary");
        String Str = String.Empty;
        foreach (KeyValuePair<String, ColumnInfo> dictInfo in Dict)
        {
            Str += "<p>键:" + dictInfo.Key + "值:列名:" + dictInfo.Value.ColumnName + "映射类:" + dictInfo.Value.ReflecClass + "映射类中方法名:" + dictInfo.Value.ReflecFunctionName + "</p>";
        }
        Response.Write(Str);
    }

   

    protected void Button2_Click(object sender, EventArgs e)
    {
        #region 测试数据(单元数据)
        DataTable dt = GetRtRmUnit();
        DataTable Syncdt = GetRmUnit();
        String Rtidentity = @"UnitIdentifier";
        String idtntity = @"UnitIdentifier";
        String EnmunType = @"UnitColumnDictionary";
        #endregion
        #region 同步前数据
        GridView3.DataSource = dt;
        GridView3.DataBind();
        GridView1.DataSource = Syncdt;
        GridView1.DataBind();
        #endregion

     RoadTeam.Pub.SyncTable.SyncDataTable(dt, Syncdt, Rtidentity, idtntity, EnmunType);

        #region 同步后数据
        GridView2.DataSource = Syncdt;
        GridView2.DataBind();
        #endregion
        #region 每一行状态
        String Str = String.Empty;
        foreach (DataRow dr in Syncdt.Rows)
        {
            Str += @"<p>" + dr.RowState.ToString() + "</p>";
        }
        Label1.Text = Str;
        #endregion

    }
}
